cmake_minimum_required(VERSION 2.8)
project(utils)

set(CMAKE_CXX_STANDARD 11)

set(LIB_MAJOR_VERSION "1")
set(LIB_MINOR_VERSION "0")
set(LIB_PATCH_VERSION "0")
set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VERSION}")

set(CMAKE_BUILD_TYPE debug)
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)

find_package(glog REQUIRED)
find_package(RapidJSON REQUIRED)

include_directories(include ${RapidJSON_INCLUDE_DIRS})

add_library(${PROJECT_NAME} SHARED src/JsonUtil.cpp src/LogUtil.cpp)
target_link_libraries(${PROJECT_NAME} glog::glog)

add_executable(someEnum src/someEnum.cpp)
target_link_libraries(someEnum ${PROJECT_NAME})
# target_compile_options(someEnum PUBLIC ${CMAKE_CXX_FLAGS} -E -C)

#add extra search paths for libraries and includes
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in")
SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "Directory where lib will install")
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}" CACHE PATH "Path to the documentation")

CONFIGURE_FILE (
    ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
    @ONLY
)

install(
    TARGETS ${PROJECT_NAME}
    ARCHIVE DESTINATION ${LIB_INSTALL_DIR}     #默认安装静态库到/usr/local/lib目录
    LIBRARY DESTINATION ${LIB_INSTALL_DIR}     #默认安装动态库到/usr/local/lib目录
)

install(
    DIRECTORY ${PROJECT_SOURCE_DIR}/include/utils DESTINATION ${INCLUDE_INSTALL_DIR}
)

install(
    FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
    DESTINATION "${LIB_INSTALL_DIR}/pkgconfig"
    COMPONENT pkgconfig
)

if(NOT TARGET uninstall)
    configure_file(
        "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
        IMMEDIATE @ONLY)

    add_custom_target(uninstall
        COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
